home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD ROM Paradise Collection 4
/
CD ROM Paradise Collection 4 1995 Nov.iso
/
win
/
rtfhelp.zip
/
RTFHMAIN.C
< prev
next >
Wrap
Text File
|
1994-11-06
|
8KB
|
303 lines
/*
======================================================================
RTFHelp Windows Help Generation Tool
(C) Copyright 1994 by J. Hlavaty
RTFHMain.c
Parses arguments, opens files and calls text parsing routine
======================================================================
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "rtfhelp.h"
struct COMMANDENTRY CommandList[NOOFCMDS] =
{
"BOLD", bold,
"BMC", bitmapcharacter,
"BOX", box,
"BROWSESEQ", browseseq,
"BUILD", build,
"CENTER", centeralign,
"CONTEXTID", contextID,
"DEFFONT", deffont,
"DEFINELINK", definelink,
"DEFINEPOPUP", definepopup, // older term
"DEFINITION", putpopup, // older term
"DEFTAB", deftab,
"FIRSTINDENT", firstlineindent,
"FONT", font,
"FONTSIZE", fontsize,
"JUST", justified,
"ITALIC", italic,
"KEEP", keep,
"KEEPNEXT", keepnext,
"KEYWORD", keyword,
"LEFT", leftalign,
"LEFTINDENT", leftindent,
"LINE", requiredlinebreak,
"LINKCONTEXT", definelink, // older term
"PAGE", newpage,
"PARA", newparagraph,
"PARD", pard,
"PLAIN", plain,
"PUTLINK", putlink,
"PUTPOPUP", putpopup,
"RIGHT", rightalign,
"RIGHTINDENT", rightindent,
"SA", spaceafter,
"SB", spacebefore,
"SL", spacebetween,
"SMALLCAPS", smallcaps,
"SPACECHAR", spacechar,
"TAB", tab,
"TB", tabbar,
"TQC", tabcenter,
"TQDEC", tabdec,
"TQR", tabright,
"TITLE", title,
"TX", tabpos,
"XREF", putlink, // older term
"XREFCONTEXT", definepopup,
"XREFID", xrefID,
"*", comment,
";", comment,
//--- undocumented tags follow
"DEFFORMAT", defformat,
"MARGB", marginbottom,
"MARGL", marginleft,
"MARGR", marginright,
"MARGT", margintop,
} ;
int main( int argc, char **argv )
{
FILE *flInput, *flOutput ;
int rc ;
int iLine = 1 ; // what line of the input file we've processed
// output logo information to user
DisplayBanner() ;
// process user parameters (passed into main)
ProcessArgs( argc, argv ) ;
// if no input file then there's nothing to do...
if ( NULL == pszInput )
{
return INVALID_NO_OF_PARAMS ;
}
// szBuffer is a temporary holding area -- copy file name
// and add extension if no extension already given
strcpy( szBuffer, pszInput ) ;
if ( !strchr( szBuffer, '.' ) )
{
strcat( szBuffer,".hdc" ) ;
}
// open input file, exit if not found...
if ( NULL == ( flInput = fopen( szBuffer,"r" ) ) )
{
printf( "Could not open input file '%s'\n", szBuffer ) ;
return FOPEN_RETURNED_NULL ;
}
// generate output file name if none is given by user
if ( NULL == pszOutput )
{
char *pos ;
// copy input file name again to buffer
strcpy( szBuffer, pszInput ) ;
pszOutput = szBuffer ;
// remove the file extension (if any) by nulling out the period delimiter
pos = strchr( pszOutput,'.' ) ;
if (pos)
*pos='\0' ;
}
else
{
strcpy( szBuffer, pszOutput ) ;
}
// if no extension given on output file, add .RTF...
if ( !strchr( szBuffer,'.' ) )
{
strcat( szBuffer,".rtf" ) ;
}
// if open of output file is not NULL, then file exists...
if ( NULL != ( flOutput = fopen( szBuffer,"r" ) ) )
{
fclose ( flOutput ) ; // close current open
// warn user if they haven't asked us not to
if ( FALSE == bOverwrite )
{
// we use szBuffer2 to not overwrite our file name in szBuffer
sprintf( szBuffer2,"Output file '%s'already exists, overwrite? (Y/N) ",
szBuffer ) ;
fputs( szBuffer2, stderr ) ;
gets( szBuffer2 ) ;
if ( 'Y' != toupper( *szBuffer2 ) )
{
fputs( "\t*** Table generation canceled\n", stderr ) ;
return USER_ABORT ;
}
else
{
fputs( "\t*** Table replaced\n", stderr ) ;
}
}
}
// try to open output file for write, exit if can't open output file
if ( NULL == ( flOutput = fopen( szBuffer,"w" ) ) )
{
printf( "Could not open output file '%s'\n", szBuffer ) ;
return FOPEN_RETURNED_NULL ;
}
// generating HDC files from RTF files not in this release of RTFHelp
if ( 0 )
{
/*
* if ( TRUE == bGeneratingHDC ) {
* // this is the code for generating...
* JH -- stubbed out of version 2.0...
* DoGeneration( flInput, flOutput ) ;
* DoSecondGeneration( &flInput, &flOutput ) ;
*/
}
else
{
// write header -- RTF group and font table
write_head( flOutput ) ;
// add to output file by parsing input file
while( TRUE )
{
if ( NULL == fgets( szBuffer,RTFH_BUFFERSIZE,flInput ) )
{
if ( feof(flInput) )
{
break ; // EOF -- we're finished
}
else
{ // some error
printf("RTFHELP: 'fgets' error\n") ;
return LIBRARY_ERROR ;
} // end IF #2
} // end IF #1
// generate RTF file for current line of input file...
rc = Tokenize( flInput, flOutput, szBuffer ) ;
if ( rc != RC_OK )
{
printf("RTFHELP: error processing line '%d'\n",iLine) ;
}
iLine++ ;
} // end WHILE loop
// close the RTF group
write_tail(flOutput) ;
}
// close our output and input files
fclose(flOutput) ;
fclose(flInput) ;
exit(RC_OK) ;
}
write_head( FILE *File )
{
char *Text = "{\\rtf1\\ansi " ;
char *Fonts = "\n\\deff0{\\fonttbl\
{\\f0\\froman Tms Rmn;}\
{\\f1\\fdecor Symbol;}\
{\\f2\\fswiss Helv;}\
{\\f3\\fmodern pica;}\
{\\f4\\fmodern Courier;}\
{\\f5\\fmodern elite;}\
{\\f6\\fmodern prestige;}\
{\\f7\\fmodern lettergothic;}\
{\\f8\\fmodern gothicPS;}\
{\\f9\\fmodern cubicPS;}\
{\\f10\\fmodern lineprinter;}\
{\\f11\\fswiss Helvetica;}\
{\\f12\\fmodern avantegarde;}\
{\\f13\\fmodern spartan;}\
{\\f14\\fmodern metro;}\
{\\f15\\fmodern presentation;}\
{\\f16\\fmodern APL;}\
{\\f17\\fmodern OCRA;}\
{\\f18\\fmodern OCRB;}\
{\\f19\\froman boldPS;}\
{\\f20\\froman emperorPS;}\
{\\f21\\froman madaleine;}\
{\\f22\\froman zapf humanist;}\
{\\f23\\froman classic;}\
{\\f24\\froman roman f;}\
{\\f25\\froman roman g;}\
{\\f26\\froman roman h;}\
{\\f27\\froman timesroman;}\
{\\f28\\froman century;}\
{\\f29\\froman palantino;}\
{\\f30\\froman souvenir;}\
{\\f31\\froman garamond;}\
{\\f32\\froman caledonia;}\
{\\f33\\froman bodini;}\
{\\f34\\froman university;}\
{\\f35\\fscript Script;}\
{\\f36\\fscript scriptPS;}\
{\\f37\\fscript script c;}\
{\\f38\\fscript script d;}\
{\\f39\\fscript commercial script;}\
}\n" ;
int rc ;
// write RTF file header info
rc = fprintf( File, "%s", Text ) ;
if ( rc < 0 )
{
printf( "RTFHELP: error from fprintf\n" ) ;
exit( LIBRARY_ERROR ) ;
}
// write font table
rc = fprintf( File, "%s", Fonts ) ;
if ( rc < 0 )
{
printf( "RTFHELP: error from fprintf\n" ) ;
exit( LIBRARY_ERROR ) ;
}
return RC_OK ;
}
write_tail( FILE *File )
{
char *Text = "}\n" ;
int rc ;
// close the RTF group
rc = fprintf( File, "%s", Text ) ;
if ( rc < 0 )
{
printf( "RTFHELP: error from fprintf\n" ) ;
exit( LIBRARY_ERROR ) ;
}
return RC_OK ;
}